export default {
    download(imageArr, firstData, callback) {

        let colorRed = 'FF0000';
        let colorYellow = 'FFC000';
        let colorLightYellow = 'FFFF00';
        let colorBlack = '000000';
        let pptx = new PptxGenJS()
        ///第一页pptx
        let slide = pptx.addSlide();

        slide.addImage({
            path: firstData.image,
            x: 0,
            y: 0,
            w: '100%',
            h: '80%'
        });

        slide.addShape(pptx.ShapeType.rect, {
            x: 0,
            y: 0,
            w: '100%',
            h: '80%',
            fill:
                { color: '003164', transparency: 50 }

        });
        slide.addImage({
            path: require('@/assets/images/pptxSBImage/imageBack/qmwlogo.png'),
            x: '86%',
            y: '4.6%',
            w: '12.4%',
            h: '9.7%'
        });

        slide.addText("浙江青墨湾能源科技有限公司",
            {
                x: 0,
                y: '81%',
                w: "100%",
                h: "7%",
                color: "363636",
                align: 'center',
                fontSize: 13.5,
                fontFace: "微软雅黑",
                bold: true,
                shadow: { type: "outer", color: "000000", blur: 1, offset: 1, angle: 45 },
                charSpacing: 7,
            }
        );

        slide.addText(firstData.dateSelected,
            {
                x: 0,
                y: '85.7%',
                w: "100%",
                h: "7%",
                color: "363636",
                align: 'center',
                fontSize: 13.5,
                fontFace: "微软雅黑",
                bold: true,
                shadow: { type: "outer", color: "000000", blur: 1, offset: 1, angle: 45 },
                charSpacing: 7,
            }
        );
        slide.addText(firstData.title, {
            x: 0,
            y: "10%",
            w: "100%",
            h: "28.6%",
            align: 'center',
            fontSize: 71,
            fontFace: "微软雅黑",
            color: "FFFFFF",
            bold: true,
            shadow: { type: "outer", color: "000000", blur: 3, offset: 3, angle: 45 },
            charSpacing: 12,
        })
        ///第二页ppt
        let slide2 = pptx.addSlide();
        this.returnHeader(slide2, "燃气安全“333”示范工程", "————温州奥林匹克体育中心", colorRed)


        slide2.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor2Page/范例示图.png'),
            x: 0,
            y: '18%',
            w: '100%',
            h: '82%'
        })
        // ///黄色矩形
        // slide2.addShape(pptx.ShapeType.rect, {
        //     x: '77.2%',
        //     y: '18%',
        //     w: '22.8%',
        //     h: '22.66666%',
        //     fill: { color: 'FFFD2C' }
        // })
        // ///橘色矩形
        // slide2.addShape(pptx.ShapeType.rect, {
        //     x: '77.2%',
        //     y: '41.66666%',
        //     w: '22.8%',
        //     h: '22.66666%',
        //     fill: { color: 'ED7D31' }
        // })

        // ///红色矩形
        // slide2.addShape(pptx.ShapeType.rect, {
        //     x: '77.2%',
        //     y: '65.33332%',
        //     w: '22.8%',
        //     h: '22.66666%',
        //     fill: { color: 'F54C43' }

        // })
        // slide2.addImage({
        //     path: require('@/assets/images/pptxSBImage/imageFor2Page/底部.png'),
        //     x: 0,
        //     y: '90.3%',
        //     w: '100%',
        //     h: '9.7%'
        // })
        ///第三页ppt
        let slide3 = pptx.addSlide()
        // this.contentsBackgroundImage(slide3)
        slide3.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor3Page/示范图.png'),
            x: 0,
            y: '0',
            w: '100%',
            h: '100%'
        })
        //第四页ppt
        let slide4 = pptx.addSlide()
        ///页眉封装
        this.returnHeader(slide4, "实际勘察与建设方案————“一场景一方案”", "(一)一级预警————地下管阀系统", colorRed)
        ///背景
        this.imageSize(slide4, 'imageFor4Page/第四页ppt背景.png')
        if (imageArr[0].GIS != '') {
            this.getImageFromInternational(slide4, imageArr[0].GIS, 0, '26.5%', '32.5%', '50.9%')
        }
        if (imageArr[0].danger[0] != undefined) {

            this.getImageFromInternational(slide4, imageArr[0].danger[0].image, '34.9%', '26.5%', '13.2%', '17%')
            this.textSize(slide4, imageArr[0].danger[0].descript, '34.9%', '43.5%', '13.2%', '10%', 8)
        }
        if (imageArr[0].danger[1] != undefined) {
            this.getImageFromInternational(slide4, imageArr[0].danger[1].image, '34.9%', '51.93%', '13.34%', '17.18%')
            this.textSize(slide4, imageArr[0].danger[1].descript, '34.9%', '69.11%', '13.2%', '10%', 8)
        }
        if (imageArr[0].danger[2] != undefined) {
            this.getImageFromInternational(slide4, imageArr[0].danger[2].image, '0', '78.4%', '15.75%', '16.15%')
            this.textSize(slide4, imageArr[0].danger[2].descript, '0%', '94.55%', '15.75%', '6%', 8)
        }
        if (imageArr[0].danger[3] != undefined) {
            this.getImageFromInternational(slide4, imageArr[0].danger[3].image, '16.75%', '78.4%', '15.75%', '16.15%')
            this.textSize(slide4, imageArr[0].danger[3].descript, '16.75%', '94.55%', '15.75%', '6%', 8)
        }
        if (imageArr[0].danger[4] != undefined) {
            this.getImageFromInternational(slide4, imageArr[0].danger[4].image, '34.9%', '78.4%', '13.34%', '16.15%')
            this.textSize(slide4, imageArr[0].danger[4].descript, '34.9%', '93.55%', '13.34%', '6%', 8)
        }
        slide4.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor4Page/示范图.png'),
            x: '50%',
            y: '18%',
            w: '50%%',
            h: '82%'
        })

        // const contentString = "2022年应急管理部：全国已经有近10万公里管道出现不同程度的老化，建设时标准低，日常维护、保养、更新不及时，风险挑战非常大。\n燃气管道一旦老化，极易发生泄漏。室外埋地管道，泄漏出来的燃气会容易渗入周围的下水道、窨井以及其他地下密闭空间，一旦遇明火，就发生燃气爆炸。"
        // this.imageSize(slide4, 'imageFor4Page/右1文字背景.png', '50.7%', '22.89%', '49.49%', '13.25%')
        // this.textSize(slide4, contentString, '50.7%', '22.89%', '49.49%', '13.25%', 8)
        // this.imageSize(slide4, 'imageFor4Page/右三个相同背景.png', '50.7%', '36.14%', '16.163%', '63.86%')
        // this.imageSize(slide4, 'imageFor4Page/案例一图片.png', '50.8%', '44.31%', '15.74%', '28.22%')
        // this.imageSize(slide4, 'imageFor4Page/右三个相同背景.png', '67.363%', '36.14%', '16.163%', '63.86%')
        // this.imageSize(slide4, 'imageFor4Page/事故案例二图片1.png', '67.363%', '44.31%', '15.74%', '14.11%')
        // this.imageSize(slide4, 'imageFor4Page/事故案例二图片2.png', '67.363%', '58.42%', '15.74%', '14.11%')
        // this.imageSize(slide4, 'imageFor4Page/右三个相同背景.png', '84.026%', '36.14%', '16.163%', '63.86%')
        // this.imageSize(slide4, 'imageFor4Page/事故相关案例图片1.png', '84.026%', '44.31%', '15.74%', '14.11%')
        // this.imageSize(slide4, 'imageFor4Page/事故相关案例图片2.png', '84.026%', '58.42%', '7.87%', '17.82%')
        // this.imageSize(slide4, 'imageFor4Page/事故相关案例图片3.png', '91.896%', '58.42%', '7.87%', '17.82%')
        ///第五页ppt
        let slide5 = pptx.addSlide()
        ///页眉封装
        this.returnHeader(slide5, "实际勘察与建设方案————“一场景一方案”", "(一)一级预警————地下管阀系统", colorRed)
        slide5.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor5Page/示范图.png'),
            x: 0,
            y: '18%',
            w: '100%',
            h: '82%'
        })
        ///背景
        // this.imageSize(slide5, 'imageFor5Page/第五页ppt背景.png')
        // this.imageSize(slide5, 'imageFor5Page/左一图片.png', '0', '24.47%', '23.65%', '32.35%')
        // this.imageSize(slide5, 'imageFor5Page/左二图片.png', '24.65%', '24.47%', '23.65%', '32.35%')
        // this.imageSize(slide5, 'imageFor5Page/左三图片.png', '0', '61.14%', '23.65%', '32.35%')
        // this.imageSize(slide5, 'imageFor5Page/左四图片.png', '24.65%', '61.14%', '23.65%', '32.35%')
        // this.imageSize(slide5, 'imageFor5Page/右一图片.png', '51.48%', '28.24%', '22.72%', '22.99%')
        // this.imageSize(slide5, 'imageFor5Page/右二图片.png', '76.07%', '28.24%', '22.72%', '22.99%')
        // this.imageSize(slide5, 'imageFor5Page/右三图片.png', '51.48%', '51.56%', '11.36%', '22.99%')
        // this.imageSize(slide5, 'imageFor5Page/右四图片.png', '62.84%', '51.56%', '11.36%', '22.99%')
        // this.imageSize(slide5, 'imageFor5Page/右五图片.png', '76.07%', '51.56%', '22.72%', '22.99%')
        // ///第六页ppt
        let slide6 = pptx.addSlide()
        ///页眉封装
        this.returnHeader(slide6, "实际勘察与建设方案————“一场景一方案”", "(二)二级预警————燃气调压网络", colorYellow)
        this.imageSize(slide6, "imageFor6Page/第六页ppt背景.png")

        ///GIS图
        if (imageArr[1].GIS != '') {
            this.getImageFromInternational(slide6, imageArr[1].GIS, 0, '26.5%', '32.5%', '50.9%')
        }
        ///隐患图片

        if (imageArr[1].danger[0] != undefined) {
            this.getImageFromInternational(slide6, imageArr[1].danger[0].image, '34.9%', '26.5%', '13.2%', '17%')
            this.textSize(slide6, imageArr[1].danger[0].descript, '34.9%', '43.5%', '13.2%', '10%', 8)
        }
        if (imageArr[1].danger[1] != undefined) {
            this.getImageFromInternational(slide6, imageArr[1].danger[1].image, '34.9%', '51.93%', '13.34%', '17.18%')
            this.textSize(slide6, imageArr[1].danger[1].descript, '34.9%', '69.11%', '13.2%', '10%', 8)
        }
        if (imageArr[1].danger[2] != undefined) {
            this.getImageFromInternational(slide6, imageArr[1].danger[2].image, '0', '78.4%', '15.75%', '16.15%')
            this.textSize(slide6, imageArr[1].danger[2].descript, '0%', '94.55%', '15.75%', '6%', 8)
        }
        if (imageArr[1].danger[3] != undefined) {
            this.getImageFromInternational(slide6, imageArr[1].danger[3].image, '16.75%', '78.4%', '15.75%', '16.15%')
            this.textSize(slide6, imageArr[1].danger[3].descript, '16.75%', '94.55%', '15.75%', '6%', 8)
        }
        if (imageArr[1].danger[4] != undefined) {
            this.getImageFromInternational(slide6, imageArr[1].danger[4].image, '34.9%', '78.4%', '13.34%', '16.15%')
            this.textSize(slide6, imageArr[1].danger[4].descript, '34.9%', '93.55%', '13.34%', '6%', 8)
        }

        slide6.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor6Page/示范图.png'),
            x: '50%',
            y: '18%',
            w: '50%%',
            h: '82%'
        })


        // this.imageSize(slide6, 'imageFor6Page/右一图片.png', '51.3%', '36.45%', '32.93%', '26.11%')
        // this.imageSize(slide6, 'imageFor6Page/右二图片.png', '85.23%', '27.59%', '13.91%', '16.91%')
        // this.imageSize(slide6, 'imageFor6Page/右三图片.png', '85.23%', '45.5%', '13.91%', '16.91%')
        // this.imageSize(slide6, 'imageFor6Page/右四图片.png', '51.3%', '68.47%', '32.84%', '29.23%')
        // this.imageSize(slide6, 'imageFor6Page/右五图片.png', '85.23%', '68.47%', '14.38%', '14.615%')
        // this.imageSize(slide6, 'imageFor6Page/右六图片.png', '85.23%', '83.085%', '14.38%', '14.615%')
        ///第七页ppt
        let slide7 = pptx.addSlide()
        this.returnHeader(slide7, "实际勘察与建设方案————“一场景一方案”", "(二)二级预警————燃气调压网络", colorYellow)
        slide7.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor7Page/示范图.png'),
            x: 0,
            y: '18%',
            w: '100%',
            h: '82%'
        })




        // this.imageSize(slide7, "imageFor7Page/第七页ppt背景.png")
        // this.imageSize(slide7, 'imageFor7Page/左一图片.png', '0', '24.47%', '23.65%', '32.35%')
        // this.imageSize(slide7, 'imageFor7Page/左二图片.png', '24.65%', '24.47%', '23.65%', '32.35%')
        // this.imageSize(slide7, 'imageFor7Page/左三图片.png', '0', '61.14%', '23.65%', '32.35%')
        // this.imageSize(slide7, 'imageFor7Page/左四图片.png', '24.65%', '61.14%', '23.65%', '32.35%')
        // this.imageSize(slide7, 'imageFor7Page/右一图片.png', '51.52%', '28.11%', '22.61%', '47.93%')
        // this.imageSize(slide7, 'imageFor7Page/右二图片.png', '76.17%', '28.11%', '22.61%', '23.965%')
        // this.imageSize(slide7, 'imageFor7Page/右三图片.png', '76.17%', '52.75%', '22.61%', '23.965%')
        ///第八页ppt
        let slide8 = pptx.addSlide()
        this.returnHeader(slide8, "实际勘察与建设方案————“一场景一方案”", "(三)三级预警————有限空间场景", colorLightYellow)
        this.imageSize(slide8, "imageFor8Page/第八页ppt背景.png")

        for (let row = 0; row < 2; row++) {
            for (let col = 0; col < 5; col++) {

                if (imageArr[2].danger[col + (row * 5)] != undefined) {
                    this.getImageFromInternational(slide8, imageArr[2].danger[col + (row * 5)].image, col * 20 + '%', row * 30 + 18 + '%', '20%', '25%',)
                    slide8.addText(imageArr[2].danger[col + (row * 5)].descript, { x: col * 20 + '%', y: row * 30 + 18 + 25 + '%', w: '20%', h: '4.5%', fontSize: 9 })
                }

            }
        }


        /// 第九页ppt
        let slide9 = pptx.addSlide()
        this.returnHeader(slide9, "实际勘察与建设方案————“一场景一方案”", "(三)三级预警————有限空间场景", colorLightYellow)
        this.imageSize(slide9, "imageFor9Page/第九页ppt背景.png")
        // this.imageSize(slide9, 'imageFor9Page/内容.png', '0', '22.88%', '100%', '77.12%')
        slide9.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor9Page/示范图.png'),
            x: '50%',
            y: '18%',
            w: '50%%',
            h: '82%'
        })

        /// 第十页ppt
        let slide10 = pptx.addSlide()
        this.returnHeader(slide10, "实际勘察与建设方案————“一场景一方案”", "(三)三级预警————有限空间场景", colorLightYellow)
        this.imageSize(slide10, "imageFor10Page/第十页ppt背景.png")
        // this.imageSize(slide10, 'imageFor10Page/内容.png', '0', '22.88%', '100%', '77.12%')
        slide10.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor7Page/示范图.png'),
            x: 0,
            y: '18%',
            w: '100%',
            h: '82%'
        })

        ///第十一页ppt
        let slide11 = pptx.addSlide()
        // this.contentsBackgroundImage(slide11)
        slide11.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor11Page/示范图.png'),
            x: 0,
            y: '0',
            w: '100%',
            h: '100%'
        })

        ///第十二页ppt
        let slide12 = pptx.addSlide()
        this.returnHeader(slide12, "二、业务服务", "(一)三类业务：培训、运维、员处置", colorBlack)
        this.imageSize(slide12, 'imageFor12Page/内容.png', '0', '22.88%', '100%', '77.12%')
        ///第十三页ppt
        let slide13 = pptx.addSlide()
        this.returnHeader(slide13, "二、业务服务", "(二)三类报警：预警、报警、告警", colorBlack)
        this.imageSize(slide13, 'imageFor13Page/内容.png', '0', '22.88%', '100%', '77.12%')
        //第十四页ppt
        let slide14 = pptx.addSlide()
        this.returnHeader(slide14, "二、业务服务", "(三)三重保障", colorBlack)
        this.imageSize(slide14, 'imageFor14Page/内容.png', '0', '22.88%', '100%', '77.12%')
        //第十五页ppt
        let slide15 = pptx.addSlide()
        slide15.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor15Page/示范图.png'),
            x: 0,
            y: '0',
            w: '100%',
            h: '100%'
        })
        // this.contentsBackgroundImage(slide15)
        //第十六页ppt
        let slide16 = pptx.addSlide()
        this.returnHeader(slide16, "三、燃气安全“333”方案", "", colorBlack, false)
        this.imageSize(slide16, 'imageFor16Page/内容.png', '0', '8.5%', '100%', '91.5%')
        //第十七页ppt
        let slide17 = pptx.addSlide()
        this.returnHeader(slide17, "三、“燃气安全+”综合数字能源系统", "", colorBlack, false)
        this.imageSize(slide17, "imageFor17Page/第十七页ppt背景.png", undefined, '8.5%', undefined, '91.5%')
        //第十八页ppt
        let slide18 = pptx.addSlide()
        this.returnHeader(slide18, "三、燃气安全“333”方案", "", colorBlack)
        slide18.addImage({
            path: require('../src/assets/images/pptxSBImage/imageFor18Page/第十八页ppt背景.png'),
            x: 0,
            y: '13.25%',
            w: '100%',
            h: '86.75%',
            transparency: 50
        })
        //生成ppt文件


        slide18.addShape(pptx.ShapeType.rect, {
            x: 1.5,
            y: 1.5,
            w: '60%',
            h: '25%',
            fill: "ED7F31"
        }
        )
        this.textSize(slide18, '"燃气安全+"以燃气为核心的综合能源安全带服务', 1.5, 1.5, '60%', '25%', 25)
        pptx.writeFile({
            fileName: 'example.pptx'
        }).then(() => {
            callback(true);
        });



    },

    // --------------------------------------------------------------------------------------------------------------------------------
    ///背景大小模版
    imageSize(slideX, pathName, x = 0, y = '18%', w = '100%', h = '82%') {
        slideX.addImage({
            path: require('../src/assets/images/pptxSBImage/' + pathName),
            x,
            y,
            w,
            h
        })
    },
    ///从网络文件获取图片
    getImageFromInternational(slideX, pathAddress, x = 0, y = '18%', w = '100%', h = '82%') {
        slideX.addImage({
            path: pathAddress,
            x,
            y,
            w,
            h
        })
    },
    //添加文本
    textSize(slideX, contentString, x, y, w, h, fontSize, fontFace = '微软雅黑', color = '000000') {
        slideX.addText(contentString, {
            x,
            y,
            w,
            h,
            fontSize,
            fontFace,
            color,
            indentLevel: 2
        })


    },
    ///目录页的背景生成方法
    contentsBackgroundImage(slideX) {
        slideX.addImage({
            path: require('@/assets/images/pptxSBImage/imageFor3Page/第三页ppt背景.png'),
            x: 0,
            y: 0,
            w: '100.2%',
            h: '100.2%'
        })
    },
    ///生成页眉的模版
    returnHeader(slideX, titleFirst, titleSecond, FontColorSet, isHaveSecondHeader = true) {
        slideX.addImage({
            path: require('@/assets/images/pptxSBImage/imageBack/页眉.png'),
            x: 0,
            y: 0,
            w: '100%',
            h: '8.5%',

        });
        slideX.addImage({
            path: require('@/assets/images/pptxSBImage/imageBack/页眉1.png'),
            x: 0,
            y: 0,
            w: '100%',
            h: '8.5%'
        });

        slideX.addText(titleFirst, {
            x: '13%',
            y: '0%',
            w: '80%',
            h: '8.5%',
            fontSize: 18,
            fontFace: '微软雅黑',
            color: 'FFFFFF',
            bold: true,
            options: {
                indentLevel: 1,

            }
        })
        if (isHaveSecondHeader == true) {
            slideX.addImage({
                path: require('@/assets/images/pptxSBImage/imageBack/页眉2.png'),
                x: 0,
                y: '8.5%',
                w: '100%',
                h: '8.5%',
            });
            slideX.addText(titleSecond, {
                x: '13%',
                y: '8.5%',
                w: '50%',
                h: '8.5%',
                fontSize: 18,
                fontFace: '微软雅黑',
                color: FontColorSet,
                bold: true,
                shadow: {
                    type: "outer",
                    color: "808080",
                    blur: 0.5,
                    angle: 15,
                    distance: 0.1,
                    offset: 1
                },

            })
        }
    }

}
